App.controller("customerListCtrl",function($scope, $rootScope, $location, $http, $compile, $stateParams, $timeout, path, publicService) {
	
	$scope.search1 = {};		//搜索参数
	$scope.search2 = {};		//搜索参数
	var index1 = 0;
	$scope.customerInfo = {};		//消费者信息
	$scope.remark =""    //备注
	$scope.customerMessage = {};	//消费者信息
	var chooseCustomer = {		//选中消费者信息
			customerId: null
	};
	
	
	$scope.company_1_show = true;			//分公司（显示）
	$scope.company_1_hidden = false;		//分公司（隐藏）
	$scope.shopName_1_hidden = false;		//专卖店（隐藏）
	
	$scope.company_2_show = true;			//分公司（显示）
	$scope.shop_2_show = true;				//分公司（显示）
	$scope.company_2_hidden = false;		//分公司（隐藏）
	
	$scope.company_shop_table_show = true;		//分公司,专卖店（table显示）
	$scope.shop_table_show = false;				//专卖店（table显示）
	
	var alertModel = {};	//alert模态框
	var numClick = 0;
	
	//初始化省
	$scope.initProvince1 = function(provinceId,cityId){
		$("#"+provinceId).kendoComboBox({
		    dataTextField: "name",
		    dataValueField: "code",
		    placeholder: "省",
		    filter: "contains",
		    dataSource: {
		      serverFiltering: true,
	          transport: {
	              read: {
	            	  type : 'GET',
	                  url: path+"/server/province",
	                  dataType : "json"
	              }
	          },
	          schema : {
					data : function(d) {
						var result = d.result;
						var obj ={};
						obj.name ="请选择";
						obj.code ="";
						result.unshift(obj)
						return result;
					}
				},
	      },
	      change: function(e) {
	    	    var valueList = this.value();
	    	    provinceCode1 = valueList;
	    	    $scope.getCityData1(cityId,valueList);
	      }
		});
	}
	
	//获取市数据
	$scope.getCityData1 = function(cityId,provinceCode,defaultVal){
		$http({
			   url: path+"/server/city/"+provinceCode,
			   method: 'GET'
		}).success(function(data){
			var result = data.result;
			var obj ={};
			obj.name ="请选择";
			obj.code ="null";
			result.unshift(obj)
			$scope.initCity1(cityId,result,defaultVal);
		}).error(function(data){
			console.log(data);   
		})
	};
	
	//初始化市
	$scope.initCity1 = function(cityId,cityData,defaultVal){
		if(cityData){
			var plugObj = $("#"+cityId).data("kendoComboBox");
			plugObj.value("");
			plugObj.setDataSource(cityData);
			if(defaultVal){
				plugObj.value(defaultVal);
			}
		}else{
			$("#"+cityId).kendoComboBox({
			    dataTextField: "name",
			    dataValueField: "code",
			    placeholder: "市",
			    filter: "contains",
			    dataSource: [],
			    change: function(e) {
			    	
			    	
		      }
			});
		}
	}
	
	$scope.initProvince1('province1','city1');			//初始化省（参与商户）
	$scope.initCity1('city1');				//初始化市（参与商户）
	
	$scope.initProvince1('province2','city2');			//初始化省（参与商户）
	$scope.initCity1('city2');				//初始化市（参与商户）
	
	
	
	//选择菜单
	$scope.chooseMenu = function(type){
		for(var i=1;i<=2;i++){
			if(i==type){
				$("#menu_"+i).addClass("active");
				$("#container_"+i).show();
				if(type=='2'&&numClick=='0'){
					numClick=1;
					$scope.search(2);
					
				}
			}else{
				$("#menu_"+i).removeClass("active");
				$("#container_"+i).hide();
			}
		}
	}
	
	if(userInfo.user_level==0){	//开发者
		$scope.shopName_1_hidden = true;
		
		$scope.chooseMenu(1);
	}else if(userInfo.user_level==3){	//三级用户
		$scope.shopName_1_hidden = true;
		
		$scope.chooseMenu(1);
	}else if(userInfo.user_level==2){	//二级用户
		$scope.company_1_show = false;
		$scope.company_2_show = false;
		
		$scope.company_1_hidden = true;
		$scope.company_2_hidden = true;
		
		$scope.company_shop_table_show = false;
		$scope.shop_table_show = true;
		
		$scope.chooseMenu(1);
	}else if(userInfo.user_level==1){	//一级用户
		$(".menuList").hide();
		
		$scope.company_2_show = false;
		$scope.shop_2_show = false;
		
		$scope.company_2_hidden = true;
		$scope.shop_2_hidden = true;

		$scope.company_shop_table_show = false;
		
		$scope.chooseMenu(2);
	}
	
	
	
	
	
	//表格对象
	$scope.gridOptions_1 = {
			dataSource : {
				transport : {
					read : {
						url : path+"/server/selectCustomerPage",
						type : 'POST',
						dataType : "json",
						contentType : "application/json"
					},
					parameterMap : function(options, operation) {
						if (operation == "read") {
							var sort = [{dir:"desc",field:"create_time"}];
							if(options.sort!=null && options.sort.length>0 ){
								if(options.sort[0].field=="createTime"){
									options.sort[0].field="create_time";
								}else{
									options.sort[0].field="create_time";
								}
								
								sort=options.sort;
							}
							
							var parameter = {
								page : options.page, //当前页
								pageSize : options.pageSize,
								param:{
									customerName: $scope.search1.customerName,
									customerPhone: $scope.search1.customerPhone,
									filiale: $scope.search1.filiale,
									province:$("#province1").data("kendoComboBox").value(),
									city:$("#city1").data("kendoComboBox").value(),
									shopName: $scope.search1.shopName,
									property: $("#userFrom_1").data("kendoDropDownList").value(),
									customerStatus:$("#userType_1").data("kendoDropDownList").value(),
									
									source: $("#customerSource_1").data("kendoDropDownList").value(),
									
									isAllot: 2,		//是否分配（1：已分配，2：未分配）
									
									sort:sort
								}
							};
							console.log('查询参数',parameter);
							return kendo.stringify(parameter);
						}
					},
				},
				pageSize : 10,
				serverPaging : true,
				serverSorting: true,
				schema : {
					data : function(d) {
						return d.data;
					},
					total : function(d) {
						return d.total; //总条数
					}
				},
			},
			pageable : {  //分页
				pageSizes: [10, 20, 50, 100],  //每页显示记录数
			  },  
			sortable: {   //排序
				//allowUnsort: false,  //允许无序
			    mode: "single"     //排序模式：single，multiple
			  },
			editable: false,  //true：单个编辑；popup：弹出新页面编辑
			dataBound: function () {   //序号
		        var rows = this.items();
		        var page = this.pager.page() - 1;
		        var pagesize = this.pager.pageSize();
		        $(rows).each(function () {
		            var index = $(this).index() + 1 + page * pagesize;
		            var rowLabel = $(this).find(".row-number");
		            $(rowLabel).html(index);
		        });
		    },
			columns : [
					{    
						title : "序号",
						field : "customerId", 
						width : "50px",
						template:"<input type='checkbox' class='recordClass_1' value='#:customerId #,#:shopId #' />"+"<span class='row-number subTitle'></span>"
					},
					{
						field : "customerName",         
						title : "姓名",     
						width : "100px"
					},
					{
						field : "customerPhone",         
						title : "联系方式",     
						width : "100px"
					},
					{
						field : "gender",         
						title : "性别",     
						width : "100px"
					},
					{
						field : "property",         
						title : "用户渠道",     
						width : "100px"
					},
					{
						field : "source",         
						title : "来源",     
						width : "100px"
					},
					{
						field : "provinceName",         
						title : "省",     
						width : "100px"
					},
					{
						field : "cityName",         
						title : "市",     
						width : "100px"
					},
					{
						field : "activityName",         
						title : "活动名称",     
						width : "100px"
					},
					{
						field : "remark",         
						title : "备注",     
						width : "100px"
					},
					{
						field : "filiale",         
						title : "分公司",     
						width : "100px",
						hidden: $scope.company_1_hidden,
						template: function(e){
					    	if(userInfo.user_level==3 && !e.filiale && e.customerPhone){
					    		return '<div class="canEdit" ng-click="assignCompany('+e.customerId+')">请选择</div>';
					    	}else{
					    		return e.filiale?e.filiale:'';
					    	}
					    },
					},
					{
						field : "shopName",         
						title : "专卖店",     
						width : "100px",
					},
					{
						field : "sellerName",         
						title : "专属顾问",     
						width : "100px",
						hidden: $scope.shopName_1_hidden,
						template: function(e){
					    	if(userInfo.user_level==2 && !e.sellerName){
					    		return '<div class="canEdit" ng-click="assignGuider('+e.customerId+')">请选择</div>';
					    	}else{
					    		return e.sellerName;
					    	}
					    },
					},
					{
						field : "createTime",         
						title : "创建时间",     
						width : "100px"
					},
					{
						field : "",         
						title : "操作",     
						width : "100px",
						template: function(e){
					    	var html = '';
					    	
					    	html += '<div class="operation" ng-click="lookDetails('+e.customerId+','+e.shopId+')">查看详情</div>';
					    	html += '<div class="operation" ng-click="userLabelDetails('+e.customerId+')">客户标签</div>';
					    	return html;
					    },
					}
			]
	};
	
	//表格对象
	$scope.getList = function(){

		$scope.gridOptions_2 = {
				dataSource : {
					transport : {
						read : {
							url : path+"/server/selectCustomerPage",
							type : 'POST',
							dataType : "json",
							contentType : "application/json"
						},
						parameterMap : function(options, operation) {
							if (operation == "read") {
								var sort = [{dir:"desc",field:"create_time"}];
								if(options.sort!=null && options.sort.length>0 ){
									if(options.sort[0].field=="createTime"){
										options.sort[0].field="create_time";
									}else{
										options.sort[0].field="create_time";
									}
									
									sort=options.sort;
								}
								
								var parameter = {
									page : options.page, //当前页
									pageSize : options.pageSize,
									param:{
										customerName: $scope.search2.customerName,
										customerPhone: $scope.search2.customerPhone,
										sellerName: $scope.search2.sellerName,
										province:$("#province2").data("kendoComboBox").value(),
										city:$("#city2").data("kendoComboBox").value(),
										filiale: $scope.search2.filiale,
										shopName: $scope.search2.shopName,
										property: $("#userFrom_2").data("kendoDropDownList").value(),
										
										customerStatus:$("#userType_2").data("kendoDropDownList").value(),
										source: $("#customerSource_2").data("kendoDropDownList").value(),
										
										isAllot: 1,		//是否分配（1：已分配，2：未分配）
										
										sort:sort
									}
								};
								console.log('查询参数',parameter);
								return kendo.stringify(parameter);
							}
						},
					},
					pageSize : 10,
					serverPaging : true,
					serverSorting: true,
					schema : {
						data : function(d) {
							return d.data;
						},
						total : function(d) {
							return d.total; //总条数
						}
					},
				},
				pageable : {  //分页
					pageSizes: [10, 20, 50, 100],  //每页显示记录数
				  },  
				sortable: {   //排序
					//allowUnsort: false,  //允许无序
				    mode: "single"     //排序模式：single，multiple
				  },
				editable: false,  //true：单个编辑；popup：弹出新页面编辑
				dataBound: function () {   //序号
			        var rows = this.items();
			        var page = this.pager.page() - 1;
			        var pagesize = this.pager.pageSize();
			        $(rows).each(function () {
			            var index = $(this).index() + 1 + page * pagesize;
			            var rowLabel = $(this).find(".row-number");
			            $(rowLabel).html(index);
			        });
			    },
				columns : [
						{    
							title : "序号",
							field : "customerId", 
							width : "50px",
							template:"<input type='checkbox' class='recordClass_2' value='#:customerId #,#:shopId #' />"+"<span class='row-number subTitle'></span>"
						},
						{
							field : "customerName",         
							title : "姓名",     
							width : "100px"
						},
						{
							field : "customerPhone",         
							title : "联系方式",     
							width : "100px"
						},
						{
							field : "gender",         
							title : "性别",     
							width : "100px"
						},
						{
							field : "property",         
							title : "用户渠道",     
							width : "100px"
						},
						{
							field : "source",         
							title : "来源",     
							width : "100px"
						},
						{
							field : "provinceName",         
							title : "省",     
							width : "100px"
						},
						{
							field : "cityName",         
							title : "市",     
							width : "100px"
						},
						{
							field : "activityName",         
							title : "活动名称",     
							width : "100px"
						},
						{
							field : "remark",         
							title : "备注",     
							width : "100px"
						},
						{
							field : "filiale",         
							title : "分公司",     
							width : "100px",
							hidden: $scope.company_2_hidden,
						},
						{
							field : "shopName",         
							title : "专卖店",     
							width : "100px",
							hidden: $scope.shop_2_hidden,
						},
						{
							field : "sellerName",         
							title : "专属顾问",     
							width : "100px"
						},
						{
							field : "createTime",         
							title : "创建时间",     
							width : "100px"
						},
						{
							field : "",         
							title : "操作",     
							width : "100px",
							template: function(e){
						    	var html = '';
						    	
						    	html += '<div class="operation" ng-click="lookDetails('+e.customerId+','+e.shopId+')">查看详情</div>';
						    	html += '<div class="operation" ng-click="userLabelDetails('+e.customerId+')">客户标签</div>';
						    	return html;
						    },
						}
				]
		}
	}
	
	//查询
	$scope.search = function(type){
		if(type=='2'){
			if(index1<1){
				$scope.getList();
				index1 +=1;
			}else{
				$scope["grid_"+type].dataSource.page(1);
			}
			
		}else{
			$scope["grid_"+type].dataSource.page(1);
		}
		
	}
	
	//全选，取消
	$scope.chooseAll = function(className,flag){
		publicService.chooseAllByClassName(className,flag);
	}
	
	//导出表格数据（1：筛选导出，2：选中导出）  
	$scope.downloadTableData = function(which,type){
		var paramObj = {};
		
		if(type==1){	//筛选导出
			if(which==1){
				paramObj = {
						page : 1, 
						pageSize : 10,
						ispage:false,
						param:{
							customerName: $scope.search1.customerName,
							customerPhone: $scope.search1.customerPhone,
							filiale: $scope.search1.filiale,
							province:$("#province1").data("kendoComboBox").value(),
							city:$("#city1").data("kendoComboBox").value(),
							shopName: $scope.search1.shopName,
							property: $("#userFrom_1").data("kendoDropDownList").value(),
							customerStatus:$("#userType_1").data("kendoDropDownList").value(),
							
							isAllot: 2,		//是否分配（1：已分配，2：未分配）
						}
				};
			}else if(which==2){
				paramObj = {
						page : 1, 
						pageSize : 10,
						ispage:false,
						param:{
							customerName: $scope.search2.customerName,
							customerPhone: $scope.search2.customerPhone,
							sellerName: $scope.search2.sellerName,
							province:$("#province2").data("kendoComboBox").value(),
							city:$("#city2").data("kendoComboBox").value(),
							filiale: $scope.search2.filiale,
							shopName: $scope.search2.shopName,
							property: $("#userFrom_1").data("kendoDropDownList").value(),
							
							customerStatus:$("#userType_1").data("kendoDropDownList").value(),
							
							isAllot: 1,		//是否分配（1：已分配，2：未分配）
						}
				};
			}
		}else if(type==2){	//选中导出
			var idArr = [];
			var ids = publicService.getChooseValueByClassName("recordClass_"+which);
			if(ids.length==0){
				$scope.alertMessage("请选择消费者！");
				return;
			}else{
				$.each(ids, function(index, OneObj){
					var idInfo = OneObj.split(",");
					var idObj = {
							customerId: idInfo[0],
							shopId: idInfo[1]
					};
					idArr.push(idObj);
				});
			}
			
			paramObj = {
					page : 1, 
					pageSize : 10,
					param:{
						ids: idArr
					}
			};
		}

		var requestUrl = path+"/server/export";		//请求路径
		var exportModule = "customer_module";		//模块名称
		var form = $("<form method='POST' action='"+requestUrl+"' target='_self'>"
						+"<input type='hidden' name='module_code' value='"+exportModule+"'/>"
						+"<input type='hidden' name='page' value='"+angular.toJson(paramObj)+"'/>"
					+"</form>");
		console.log("【表单参数】",form.serializeArray());
	    $(document.body).append(form);
	    form.submit();	
	}
	
	//提示信息
	$scope.alertMessage = function(message){
		alertModel.pannel = jqueryAlert({
			content: message,
			modal: true
		});
	}
	
	//分配分公司
	$scope.assignCompany = function(customerId){
		chooseCustomer.customerId = customerId;
		$scope.getCustomerInstallAddress(1,customerId);	//获取消费者安装地址
		$scope.companyWindow.center().open();   //打开弹框
	}
	
	//获取公司数据
	$scope.getCompanyDataByCode = function(areaCode){
		var postParam = {
				region_code: areaCode
		};
		
		$http({
			   url: path+"/server/selectFilialeByCode",
			   method: 'POST',   
			   data: angular.toJson(postParam)
		}).success(function(data){
			$scope.initCompany(data.result);
		}).error(function(data){
			console.log(data);   
		})
	};
	
	//初始化公司
	$scope.initCompany = function(dataList){
		if(dataList){
			var plugObj_company = null;
			plugObj_company = $("#company").data("kendoDropDownList");
			
			plugObj_company.value("");
			plugObj_company.setDataSource(dataList);
		}else{
			$("#company").kendoDropDownList({
				  dataTextField: "filialeName",
				  dataValueField: "filialeId",
				  optionLabel: "请选择分公司",
				  dataSource: []
			});
		}
	};
	
	//指定公司提交
	$scope.assignCompanySubmit = function(){
		var postParam = {
				customerId: chooseCustomer.customerId,
				filialeId: $("#company").data("kendoDropDownList").value()
		};
		
		if(!postParam.filialeId){
			$scope.alertMessage("请选择分公司！");
			return;
		}
		
		$http({
			   url: path+'/server/allotFiliale',
			   method: 'POST',   
			   data: angular.toJson(postParam)
		}).success(function(data){
			if(data.code==0){
				$scope.companyWindow.close();
				$scope.alertMessage("成功！");
				$scope.search(1);
				$scope.search(2);
				$scope.chooseMenu(2);
			}else{
				$scope.alertMessage("失败！");
			}
		}).error(function(data){
			console.warn(data);   
		})
	};
	
	//分配导购
	$scope.assignGuider = function(customerId){
		chooseCustomer.customerId = customerId;
		$scope.getCustomerInstallAddress(2,customerId);	//获取消费者安装地址
		$scope.guiderWindow.center().open();   //打开弹框
	}
	
	//初始化省
	$scope.initProvince = function(type){
		$("#province_2").kendoComboBox({
		    dataTextField: "name",
		    dataValueField: "code",
		    placeholder: "省",
		    filter: "contains",
		    dataSource: {
	          transport: {
	              read: {
	            	  type : 'GET',
	                  url: path+"/server/province",
	                  dataType : "json"
	              }
	          },
	          schema : {
					data : function(d) {
						return d.result;
					}
				},
	      },
	      change: function(e) {
	    	    var value = this.value();
	    	    if(!isNaN(Number(value))){
	    	    	$scope.getCityData(type,value);
	    	    }
	      }
		});
	};
   
	//获取市数据
	$scope.getCityData = function(type,provinceCode,defaultVal){
		$http({
			   url: path+"/server/city/"+provinceCode,
			   method: 'GET'
		}).success(function(data){
			$scope.initCity(type,data.result,defaultVal);
		}).error(function(data){
			console.log(data);   
		})
	};
	
	//初始化市
	$scope.initCity = function(type,cityData,defaultVal,changeCallback){
		if(cityData){
			var plugObj_city = $("#city_2").data("kendoComboBox");
			plugObj_city.value("");
			plugObj_city.setDataSource(cityData);
			if(defaultVal){
				plugObj_city.value(defaultVal);
			}
			
			//区（值清空）
			var plugObj_area = null;
			if(type==1){		//区（单选）
				plugObj_area = $("#area_2").data("kendoComboBox");
			}else if(type==2){	//区（多选）
				plugObj_area = $("#area_2").data("kendoMultiSelect");
			}
			plugObj_area.value("");
			plugObj_area.setDataSource([]);
		}else{
			$("#city_2").kendoComboBox({
			    dataTextField: "name",
			    dataValueField: "code",
			    placeholder: "市",
			    filter: "contains",
			    dataSource: [],
			    change: function(e) {
		    	    var value = this.value();
		    	    if(!isNaN(Number(value))){
		    	    	$scope.getAreaData(type,value);
		    	    	if(changeCallback){
		    	    		changeCallback(value);
		    	    	}
		    	    }
			    }
			});
		}
	}
	
	//获取区数据
	$scope.getAreaData = function(type,cityCode,defaultVal){
		$http({
			   url: path+"/server/county/"+cityCode,
			   method: 'GET'
		}).success(function(data){
			var allArea = {code:cityCode,name:"全城"};  //全城
			data.result.unshift(allArea);
			
			$scope.initArea(type,data.result,defaultVal);
		}).error(function(data){
			console.log(data);   
		})
	};

	//初始化区
	$scope.initArea = function(type,areaData,defaultVal){
		if(areaData){
			var plugObj_area = null;
			if(type==1){		//区（单选）
				plugObj_area = $("#area_2").data("kendoComboBox");
			}else if(type==2){	//区（多选）
				plugObj_area = $("#area_2").data("kendoMultiSelect");
			}
			
			plugObj_area.value("");
			plugObj_area.setDataSource(areaData);
			if(defaultVal){
				plugObj_area.value(defaultVal);
			}
		}else{
			if(type==1){		//区（单选）
				$("#area_2").kendoComboBox({
      				  dataTextField: "name",
      				  dataValueField: "code",
      				  placeholder: "区",
      				  filter: "contains",
      				  dataSource: [],
      				  change: function(e) {
    			    	if(this.dataItem()){
    			    		var value = this.dataItem().code;
    			    		$scope.getShopDataByCode(value);
    			    	}
      				  }
      			});
			}else if(type==2){	//区（多选）
				$("#area").kendoMultiSelect({
      				  dataTextField: "name",
      				  dataValueField: "code",
      				  placeholder: "区",
      				  filter: "contains",
      				  dataSource: []
      			});
			}
		}
	};
	
	//获取专卖店数据
	$scope.getShopDataByCode = function(areaCode){
		var postParam = {
				region_code: areaCode
		};
		
		$http({
			   url: path+"/server/selectShopByCode",
			   method: 'POST',   
			   data: angular.toJson(postParam)
		}).success(function(data){
			$scope.initShop(data.result);
		}).error(function(data){
			console.log(data);   
		})
	};
	
	//初始化专卖店
	$scope.initShop = function(dataList){
		if(dataList){
			var plugObj_shop = null;
			plugObj_shop = $("#shop").data("kendoDropDownList");
			
			plugObj_shop.value("");
			plugObj_shop.setDataSource(dataList);
		}else{
			$("#shop").kendoDropDownList({
				  dataTextField: "shopName",
				  dataValueField: "shopId",
				  optionLabel: "请选择专卖店",
				  dataSource: [],
				  change: function(e) {
			    	    var value = this.value();
			    	    if(!isNaN(Number(value))){
			    	    	$scope.getGuiderData(value);
			    	    }
				  }
			});
		}
	};
	
	//获取导购数据
	$scope.getGuiderData = function(shopId){
		var postParam = {
				shopId: shopId
		};
		
		$http({
			   url: path+"/server/selectShopSeller",
			   method: 'POST',   
			   data: angular.toJson(postParam)
		}).success(function(data){
			$scope.initGuider(data.result);
		}).error(function(data){
			console.log(data);   
		})
	};
	
	//初始化导购
	$scope.initGuider = function(dataList){
		if(dataList){
			var plugObj_guider = null;
			plugObj_guider = $("#guider").data("kendoDropDownList");
			
			plugObj_guider.value("");
			plugObj_guider.setDataSource(dataList);
		}else{
			$("#guider").kendoDropDownList({
				  dataTextField: "sellerName",
				  dataValueField: "sellerId",
				  optionLabel: "请选择导购人员",
				  dataSource: []
			});
		}
	};
	
	//指定导购提交
	$scope.assignGuiderSubmit = function(){
		var postParam = {
				customerId: chooseCustomer.customerId,
				shopId: $("#shop").data("kendoDropDownList").value(),
				sellerId: $("#guider").data("kendoDropDownList").value()
		};
		
		if(!postParam.shopId){
			$scope.alertMessage("请选择专卖店！");
			return;
		}
		if(!postParam.sellerId){
			$scope.alertMessage("请选择导购！");
			return;
		}
		
		$http({
			   url: path+'/server/addCustomerSeller',
			   method: 'POST',   
			   data: angular.toJson(postParam)
		}).success(function(data){
			if(data.code==0){
				$scope.guiderWindow.close();
				$scope.alertMessage("成功！");
				$scope.search(1);
				$scope.search(2);
				$scope.chooseMenu(2);
			}else{
				$scope.alertMessage("失败！");
			}
		}).error(function(data){
			console.warn(data);   
		})
	};
	

	
	//查看详情
	$scope.lookDetails = function(customerId,shopId){	
		var paramObj = {
				customerId: customerId,
				shopId: shopId
		};
		
		$http({
			   url:	path+'/server/selectCustomerDetail',
			   method: 'POST',   
			   data: angular.toJson(paramObj)
		}).success(function(data){
			if(data.code==0){
				$scope.customerInfo = data.result;
				$scope.customerWindow.center().open();   //打开弹框
			}else{
				$scope.alertMessage("失败！");
			}
		}).error(function(data){
			alert(data);   
		})
	}
	
	//编辑导购人员
	$scope.editSeller = function(customerId,sellerId){	
		var paramObj = {
				customerId: customerId,
				sellerId: sellerId
		};
		
		$http({
			   url:	path+'/server/addCustomerSeller',
			   method: 'POST',   
			   data: angular.toJson(paramObj)
		}).success(function(data){
			if(data.code==0){
				$scope.search();
			}else{
				$scope.alertMessage("失败！");
			}
		}).error(function(data){
			alert(data);   
		})
	}
	
	//获取消费者安装地址
	$scope.getCustomerInstallAddress = function(type,customerId){	
		var paramObj = {
				customerId: customerId
		};
		
		$http({
			   url:	path+'/server/selectCustomerInstallAddress',
			   method: 'POST',   
			   data: angular.toJson(paramObj)
		}).success(function(data){
			if(data.code==0){
				$scope.customerMessage = data.result;
				
				if(type==2){	//分配导购
					var region_code = data.result.region_code;
					var codeArr = region_code.split(",");
					$("#province_2").data("kendoComboBox").value(codeArr[0]);
					$scope.getCityData(1,codeArr[0],codeArr[1]);
					$timeout(function(){
						$scope.getAreaData(1,codeArr[1]);
				    }, 300);
					$('#province_2').data("kendoComboBox").readonly(true);
				}
			}else{
				
			}
		}).error(function(data){
			alert(data);   
		})
	}
	

	publicService.initUserForm("userFrom_1");		//初始化【用户渠道】
	publicService.initUserType("userType_1");		//初始化【用户类型】
	publicService.initCustomerSource("customerSource_1");		//初始化【消费者来源】
	
	publicService.initUserForm("userFrom_2");		//初始化【用户渠道】
	publicService.initUserType("userType_2");		//初始化【用户类型】
	publicService.initCustomerSource("customerSource_2");		//初始化【消费者来源】
	
	publicService.initProvince(1);		//初始化省
	publicService.initCity(1,null,null,null,true);			//初始化市
	publicService.initArea(1,null,null,$scope.getCompanyDataByCode);			//初始化区
	$scope.initCompany();		//初始化公司
	
	$scope.initProvince(1);		//初始化省
	$scope.initCity(1);			//初始化市
	$scope.initArea(1);			//初始化区
	$scope.initShop();			//初始化专卖店
	$scope.initGuider();		//初始化导购
	
	

	
	$scope.initAge = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: 0,
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "50后"
		             },
		             {
		            	value: 2,
		 				text: "60后"
		             },
		             {
		            	value: 3,
		 				text: "70后"
		             },
		             {
		            	value: 4,
		 				text: "80后"
			         },
			         {
		            	value: 5,
		 				text: "90后"
				     },
				     {
		            	value: 6,
		 				text: "00后"
					 }
            ]
		});
	}
	
	$scope.initIncome = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: 0,
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "高"
		             },
		             {
		            	value: 2,
		 				text: "中"
		             },
		             {
		            	value: 3,
		 				text: "低"
		             }
            ]
		});
	}
	
	$scope.initMarriage = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: 0,
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "已婚已育"
		             },
		             {
		            	value: 2,
		 				text: "已婚未育"
		             },
		             {
		            	value: 3,
		 				text: "未婚"
		             }
            ]
		});
	}
	
	$scope.initStyle = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: 0,
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "现代风格"
		             },
		             {
		            	value: 2,
		 				text: "简欧风格"
		             },
		             {
		            	value: 3,
		 				text: "中式风格"
		             },
		             {
		            	value: 4,
		 				text: "田园风格"
		             },
		             {
		            	value: 5,
		 				text: "地中海风格"
		             },
		             {
		            	value: 6,
		 				text: "简约风格"
		             }
            ]
		});
	}
	
	$scope.initTexture = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: 0,
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "实木地板"
		             },
		             {
		            	value: 2,
		 				text: "强化地板"
		             },
		             {
		            	value: 3,
		 				text: "实木复合地板"
		             }
            ]
		});
	}
	
	$scope.initColor = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
					{
						value: 0,
						text: "请选择"
					 },
					 {
						value: 1,
						text: "深色调"
					 },
					 {
						value: 2,
						text: "浅色调"
					 },
					 {
						value: 3,
						text: "冷色调"
					 },
					 {
						value: 4,
						text: "暖色调"
					 },
					 {
						value: 5,
						text: "黑色"
					 },
					 {
						value: 6,
						text: "褐色"
					 },
					 {
						value: 7,
						text: "黄色"
					 }
            ]
		});
	}
	
	$scope.initClassify = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
					{
						value: 0,
						text: "请选择"
					 },
					 {
						value: 1,
						text: "个人客户"
					 },
					 {
						value: 2,
						text: "企业客户"
					 },
					 {
						value: 3,
						text: "新客户"
					 },
					 {
						value: 4,
						text: "老客户"
					 },
					 {
						value: 5,
						text: "意向客户"
					 },
					 {
						value: 6,
						text: "流失客户"
					 },
					 {
						value: 7,
						text: "有兴趣购买的客户"
					 },
					 {
						value: 8,
						text: "考虑、犹豫的客户"
					 },
					 {
						value: 9,
						text: "暂时不买的客户"
					 },
					 {
						value: 10,
						text: "报过价的客户"
					 }
            ]
		});
	}
	
	$scope.initShoppinge = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: 0,
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "注重品质"
		             },
		             {
		            	value: 2,
		 				text: "注重价格"
		             },
		             {
		            	value: 3,
		 				text: "注重服务"
		             },
		             {
		            	value: 4,
		 				text: "促销敏感度"
		             }
            ]
		});
	}
	
	$scope.initCharacter = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: 0,
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "内向"
		             },
		             {
		            	value: 2,
		 				text: "外向"
		             }
            ]
		});
	}
	
	$scope.initAreaSize = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: 0,
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "60平米"
		             },
		             {
		            	value: 2,
		 				text: "90平米"
		             },
		             {
		            	value: 3,
		 				text: "120平米"
		             }
            ]
		});
	}
	
	$scope.initTime = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: 0,
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "一月后"
		             },
		             {
		            	value: 2,
		 				text: "三月后"
		             },
		             {
		            	value: 3,
		 				text: "半年后"
		             }
            ]
		});
	}
	
	$scope.initPurpose = function(containerId){
		$("#"+containerId).kendoDropDownList({
			dataTextField: "text",
		    dataValueField: "value",
		    dataSource: [
		             {
		            	value: 0,
		 				text: "请选择"
		             },
		             {
		            	value: 1,
		 				text: "家用"
		             },
		             {
		            	value: 2,
		 				text: "商用"
		             }
            ]
		});
	}
	//客户标签
	$scope.userLabelDetails = function(customerId){	
		chooseCustomer.customerId = customerId
//		
//		var postParam = {
//				customerId:$scope.customerID,
//				age_hierarchy:$("#age").data("kendoDropDownList").value(),
//			  	income_hierarchy:$("#income").data("kendoDropDownList").value(),
//			  	marriage:$("#marriage").data("kendoDropDownList").value(),
//			  	style:$("#style").data("kendoDropDownList").value(),
//			  	texture:$("#texture").data("kendoDropDownList").value(),
//			  	color:$("#color").data("kendoDropDownList").value(),
//			  	customer_classify:$("#classify").data("kendoDropDownList").value(),
//			  	shopping_preference:$("#shoppin").data("kendoDropDownList").value(),
//			  	character:$("#character").data("kendoDropDownList").value(),
//			  	hous_area:$("#areaSize").data("kendoDropDownList").value(),
//			  	decorate_time:$("#time").data("kendoDropDownList").value(),
//			  	shopping_purpose:$("#purpose").data("kendoDropDownList").value(),
//			  	remark:$("#remark").data("kendoDropDownList").value()
//		};
//		
//		$http({
//			   url: path+"/server/selectCustomerProperty",
//			   method: 'POST',   
//			   data: angular.toJson(postParam)
//		}).success(function(data){
//			$scope.alertMessage("成功！");
//		}).error(function(data){
//			console.log(data);   
//		})
		
		$http({
			   url:	path + "/server/selectCustomerProperty/"+customerId,		//1:行业，2:品类，3:品牌
			   method: 'GET' 
		}).success(function(data){
			if(data.code==0){
				var classData = data.result;
				
				$("#age").data("kendoDropDownList").value(classData.age_hierarchy)
			  	$("#income").data("kendoDropDownList").value(classData.income_hierarchy)
			  	$("#marriage").data("kendoDropDownList").value(classData.marriage)
			  	$("#style").data("kendoDropDownList").value(classData.style)
			  	$("#texture").data("kendoDropDownList").value(classData.texture)
			  	$("#color").data("kendoDropDownList").value(classData.color)
			  	$("#classify").data("kendoDropDownList").value(classData.customer_classify)
			  	$("#shoppin").data("kendoDropDownList").value(classData.shopping_preference)
			  	$("#character").data("kendoDropDownList").value(classData.character)
			  	$("#areaSize").data("kendoDropDownList").value(classData.hous_area)
			  	$("#time").data("kendoDropDownList").value(classData.decorate_time)
			  	$("#purpose").data("kendoDropDownList").value(classData.shopping_purpose)
			  	$scope.remark = classData.remark

			}else{
				console.log("失败！");
			}
		}).error(function(data){
			console.warn(data);   
		})
		
		
		
		$scope.userLabelWindow.center().open();   //打开弹框
	}
	//获取公司数据
	$scope.updateCustomerProperty = function(){
		var postParam = {
				customerId:chooseCustomer.customerId,
				age_hierarchy:$("#age").data("kendoDropDownList").value(),
			  	income_hierarchy:$("#income").data("kendoDropDownList").value(),
			  	marriage:$("#marriage").data("kendoDropDownList").value(),
			  	style:$("#style").data("kendoDropDownList").value(),
			  	texture:$("#texture").data("kendoDropDownList").value(),
			  	color:$("#color").data("kendoDropDownList").value(),
			  	customer_classify:$("#classify").data("kendoDropDownList").value(),
			  	shopping_preference:$("#shoppin").data("kendoDropDownList").value(),
			  	character:$("#character").data("kendoDropDownList").value(),
			  	hous_area:$("#areaSize").data("kendoDropDownList").value(),
			  	decorate_time:$("#time").data("kendoDropDownList").value(),
			  	shopping_purpose:$("#purpose").data("kendoDropDownList").value(),
			  	remark:$scope.remark
		};
		
		$http({
			   url: path+"/server/updateCustomerProperty",
			   method: 'POST',   
			   data: angular.toJson(postParam)
		}).success(function(data){
			$scope.alertMessage("成功！");
			$scope.userLabelWindow.center().close();   //打开弹框
			
			$("#age").data("kendoDropDownList").value(0)
		  	$("#income").data("kendoDropDownList").value(0)
		  	$("#marriage").data("kendoDropDownList").value(0)
		  	$("#style").data("kendoDropDownList").value(0)
		  	$("#texture").data("kendoDropDownList").value(0)
		  	$("#color").data("kendoDropDownList").value(0)
		  	$("#classify").data("kendoDropDownList").value(0)
		  	$("#shoppin").data("kendoDropDownList").value(0)
		  	$("#character").data("kendoDropDownList").value(0)
		  	$("#areaSize").data("kendoDropDownList").value(0)
		  	$("#time").data("kendoDropDownList").value(0)
		  	$("#purpose").data("kendoDropDownList").value(0)
		  	$scope.remark = ""
		}).error(function(data){
			console.log(data);   
		})
	};
	
	$scope.initAge("age");
	$scope.initIncome("income");
	$scope.initMarriage("marriage");
	$scope.initStyle("style");
	$scope.initTexture("texture");
	$scope.initColor("color");
	$scope.initClassify("classify");
	$scope.initShoppinge("shoppin");
	$scope.initCharacter("character");
	$scope.initAreaSize("areaSize");
	$scope.initTime("time");
	$scope.initPurpose("purpose");
	
	
	
});